function H = lpfilter(tipus, M, N, D0, n)
% LPFILTER computes frequency domain lowpass filters
% H = LPFILTER(TYPE, M,N,D0,N) creates the transfer
% function of a lowpass filter, H, of the specified TYPE and
% size (M-by-N). To view the filter as an image or mesh
% plot, it should be centered using H=fftshift(H).
%
% Valid values for TYPE, DO and n are:
%
% 'ideal' ideal lowpass filter with cutoff frequency D0. n
% need not be supplied. D0 must be positive.
%
% 'btw' Butterworth lowpass filter of order n, and cutoff
% D0. The default value for n is 1.0. D0 must be
% positive.
%
% 'gauss' gaussian lowpass filter with cutoff (standard
% deviation) D0. n need not be supplied. D0 must
% be positive.

% C = [(N + 1) / 2.0 , (M + 1) / 2.0 ];
C = [1, 1];
H = zeros(N, M);
if strcmp(tipus, 'ideal') == 1
    for i = 1:1:N
        for j = 1:1:M
            if my_dist(C, [i, j]) <= D0;
                H(i, j) = 1;
            end
        end
    end
elseif strcmp(tipus, 'btw') == 1
    for i = 1:1:N
        for j = 1:1:M
            c = my_dist(C, [i, j]) / D0;
            H(i, j) = 1 / (1 + c^ (2 * n));
        end
    end
else
    for i = 1:1:N
        for j = 1:1:M
            d = my_dist(C, [i, j]);
            c = -(d^2) / (2 * D0^2);
            H(i, j) = exp(1) ^ c;
        end
    end
end
